﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows;
using System.Linq;
using OfficeOpenXml;

namespace ToolExcelPub
{
    public static partial class XTool
    {
        public static void OutCsharpPclass()
        {
            if (!OutputCsharpNeed) return;

            ShowInfo("OutCsharpPclass!");

            string pathServer = PathCsharp + "\\" + "ConfSvPclass.cs";
            string pathClient = PathCsharp + "\\" + "ConfClientPclass.cs";

            var sbw = new StringBuilder();

            sbw.AppendLine(NoteGenerated);
            sbw.AppendLine($"using System.Collections.Generic;");
            sbw.AppendLine(NamespaceServer);
            sbw.AppendLine($"{{");

            foreach (var item in DictXPclassInfo.Values)
            {
                var sbnode = new StringBuilder();
                sbnode.AppendLine($"\t// {item.Desc}");
                sbnode.AppendLine($"\tpublic class {item.Name}");
                sbnode.AppendLine($"\t{{");
                foreach (var item2 in item.ListNode)
                {
                    sbnode.AppendLine($"\t\t// {item2[2]}");
                    sbnode.AppendLine($"\t\tpublic {item2[0]} {item2[1]};");
                }
                sbnode.AppendLine($"\t}}");
                string stnode = sbnode.ToString();
                sbw.Append(stnode);
            }

            sbw.AppendLine($"}}");

            //服务器
            {
                ToolGlobal.WriteNewFile(pathServer, sbw.ToString());
            }
            //客户端
            {
                var sbwc = sbw.Replace(NamespaceServer, NamespaceClient);
                ToolGlobal.WriteNewFile(pathClient, sbwc.ToString());
            }
        }
    }
}
